package com.yuq.sunrise.common.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ModelAttribute;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @author ：yuq
 * @date ：Created in 2019/6/8 23:09
 * @description：Controller公共组件
 * @modified By：
 * @version: 1.0$
 */
public abstract class AbstractController {

    /**
     * create by: yuq
     * description:
     * slf4j是对所有日志框架制定的一种规范、标准、接口，并不是具体的实现，所以为了实现通用这里采用slf4j，
     * 当项目需要更换日志框架的时候，只需要更换jar和配置，不需要更改相关java代码
     * create time: 2019-06-08 23:18
     *
     * @param null
     * @return 
     */
    protected Logger logger = LoggerFactory.getLogger(getClass());

    protected HttpServletRequest request;

    protected HttpServletResponse response;

    protected HttpSession session;

    /**
     * create by: yuq
     * description: 初始化请求时的request，response，session
     * create time: 2019-06-08 23:25
     *
     * @param
     * @return
     */
    @ModelAttribute
    public void setReqAndRes(HttpServletRequest request, HttpServletResponse response) {
        this.request = request;
        this.response = response;
        this.session = request.getSession();
    }

    /**
     * create by: yuq
     * description: 设置session值
     * create time: 2019-06-08 23:25
     *
     * @param key, obj
     * @return
     */
    protected void setSession(String key, Object obj) {
        session.setAttribute(key, obj);
    }

    /**
     * create by: yuq
     * description: 设置request值
     * create time: 2019-06-08 23:25
     *
     * @param key, obj
     * @return
     */
    protected void setRequest(String key, Object obj) {
        request.setAttribute(key, obj);
    }

    /**
     * create by: yuq
     * description: 获取request值,返回String
     * create time: 2019-06-08 23:26
     *
     * @param arg0
     * @return
     */
    protected String getReqString(String arg0) {
        return request.getParameter(arg0);
    }

}
